﻿#pragma once


#include <QDialog>
#include <QPushButton>
#include "QListView"
#include "QStringListModel"
#include "QFileDialog"
#include "QMessageBox"
#include "QApplication"
#include "QVBoxLayout"
#include <QDesktopWidget>
#include <QLibrary>
#include <QApplication>
#include <QLabel>
#include <QComboBox>
#include "QListView"
#include "QStringListModel"
#include "QLineEdit"
#include "QSpinBox"
#include "QRadioButton"
#include <QSettings>

#include "commonfunction.h"



using namespace std;

#include "qt_graphics_view.h"
#include "qt_graphics_shape_rectangle.h"

#include "dl_3.h"
#include "qwidget_dl_para1.h"
#include "qwidget_dl_para2.h"

struct DefectStandard
{
	string name="";
	float threshold_score=0;
	float threshold_size=0;
};

struct DetectionStandard
{
    string name="";
    float threshold_score=0;
    float threshold_size_min=0;
	float threshold_size_max = 0;
    int   threshold_number =1;
};


class Function_dl_3 :public QDialog
{
public:
	vector<GraphicsShapeRectangleCirce*> m_vector_graphics_shape_rectangle;
    vector<GraphicsShapeRectangleCirce*> m_vector_rectangle_ear;
	int m_camera_index = 0;
	int m_detection_index = 0;
    QSettings* m_qsettings;
    QString m_section   = "";
	QString m_save_image_dir;
    AIDll* m_dl=nullptr ;
	bool m_state = false;
     
	QtQGraphicsView* m_view ;

    QPushButton* m_pushbutton_open_model;
    QLabel     * m_qlabel_model_path;
    QString RetrainedModelFileName = "";

    


    QPushButton* m_pushbutton_show_orign_image;
    QPushButton* m_pushbutton_detection;
    QPushButton* m_pushbutton_save_parameter;
    QPushButton* m_pushbutton_return;

    QLabel* m_qlabel_message;

    int m_result;

    int row1, column1, row2, column2;
    int ret, message;

    int m_size_error_now;

    Mat m_image;
	
    Mat m_show_image;
    
    QWidgetDlPara1* m_qwidget_dl_para1 = nullptr;

	
	vector<AIResult> result_defect;
	vector<DefectStandard> m_vector_defect_standard;

	QComboBox* m_qcombox_unuse_use_ear;
	int m_unuse_use_ear;
	QWidgetDlPara2* m_qwidget_dl_para2 = nullptr;
	vector<AIResult> result_ear;
	vector<DetectionStandard> m_vector_ear_standard;

public:
    explicit Function_dl_3(QDialog *parent = nullptr, QSettings* qsettings = nullptr,QString section="",int camera_index=0,int detection_index=0) ;
    ~Function_dl_3() ;
    void detectionImage();
    int detection(Mat image, QString& message);
	void draw(Mat image_in,Mat& image_out);
    void loadParameter();
    void saveParameter();
    bool showDialog();
    void loadmodel();
    void save_dl_prar1(QWidgetDlPara1* roi_sqllite, vector<DefectStandard>& vector_defect_standard);
    void save_dl_prar2(QWidgetDlPara2* roi_sqllite, vector<DetectionStandard>& vector_defect_standard);
};
#pragma execution_character_set("utf-8")
